package com.cc.study.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.Ordered;

public class PostProcessor2 implements BeanPostProcessor,Ordered {

    //可以在初始化 bean 的之前和之后实现更复杂的逻辑。
    //在Init-method的前后执行
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization2:" + beanName);
        ((InitHelloWorld)bean).getMessage();
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization2:" + beanName);
        ((InitHelloWorld)bean).getMessage();
        return bean;
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
